package byx.container.annotation.demo.ObserverDemo;

import byx.container.annotation.PackageContainer;
import byx.container.core.Container;
import org.junit.jupiter.api.Test;

import java.util.Set;

import static org.junit.jupiter.api.Assertions.assertEquals;

/**
 * 观察者模式
 */
public class ObserverDemo {
    @Test
    public void test() {
        Container container = new PackageContainer();

        Flag.set.clear();
        Subject subject = container.getObject(Subject.class);
        assertEquals(Set.of("Observer1: initial", "Observer2: initial", "Observer3: initial"), Flag.set);

        Flag.set.clear();
        subject.setData("hello");
        assertEquals(Set.of("Observer1: hello", "Observer2: hello", "Observer3: hello"), Flag.set);
    }
}
